/*
 * @author 宋辉辉
 * @description element消息提示封装，解决多个消息同时存在问题
 * @api 无
 * @since 2021年12月6日14:41
 * @update 
 * @modifier 
 * @bug 
 * @version v1.0.0
 */

import { Message } from 'element-ui'

let messageInstance = null

const resetMessage = options => {
  if (messageInstance) {
    messageInstance.close()
  }
  messageInstance = Message(options)
  return messageInstance
}

['error', 'success', 'info', 'warning'].forEach(type => {
  resetMessage[type] = options => {
    if (typeof options == 'string') {
      options = {
        message: options
      }
    }
    options.type = type
    return resetMessage(options)
  }
})

export const message = resetMessage
